/**
 * @(#)SeachDataController.java 2017年6月2日
 * Copyright(C) 2017年6月2日 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.action;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.domian.statistics.IpreqImsiVO;
import org.jsbd.boss.enums.LoginTypeEnum;
import org.jsbd.boss.service.IIpreqImsiService;
import org.jsbd.boss.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ipreq用户下发、回转量统计数据展示controller
 * 
 * @author <a href="mailto:wangjunbiao@zhexinit.com" >王俊标</a>
 * @version 1.0.0
 */
@Controller
@RequestMapping("/ipreq/imsi")
public class IpreqImsiController {
	public static final Logger LOGGER = LoggerFactory.getLogger(IpreqImsiController.class);

	@Autowired
	private IIpreqImsiService ipreqImsiService;

	/**
	 * ipreq用户下发、回转量统计数据展示页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "list")
	public String list(Model model) throws Exception {
		return "/ipreq/ipreqList";
	}

	/**
	 * ipreq用户下发、回转量统计数据
	 * 
	 * @param page
	 *            分页信息
	 * @param
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/listJson")
	public Map<String, Object> listJson(DataGridModel page, String startDate, String endDate) throws Exception {
		if (StringUtils.isBlank(startDate) && StringUtils.isBlank(endDate)) {
			startDate = DateUtil.getDayBeforeDate(DateUtil.DATE_PATTEN_YYMMDD, 30);
		}
		if (!StringUtils.isBlank(startDate)) {
			startDate = startDate.replaceAll("-", "");
		}
		if (!StringUtils.isBlank(endDate)) {
			endDate = endDate.replaceAll("-", "");
		}
		return ipreqImsiService.getIreqImsiData(page, startDate, endDate);
	}

	/**
	 * ipreq用户下发、回转量详情
	 * 
	 * @param day
	 *            日期
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getDetail")
	public String getDetail(Model model, String day) {
		List<IpreqImsiVO> list = ipreqImsiService.getIreqImsiDetail(day);
		for (IpreqImsiVO vo : list) {
			vo.setLoginName(LoginTypeEnum.valueOf(vo.getLoginType()).getName());
		}
		model.addAttribute("list", list);
		return "/ipreq/ipreqDetail";
	}

	/**
	 * client_info用户数、下发量、回转量统计数据展示页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "clientInfolist")
	public String clientInfolist(Model model) throws Exception {
		return "/clientinfo/clientInfoList";
	}

	/**
	 * client_info用户数、下发量、回转量统计数据
	 * 
	 * @param page
	 *            分页信息
	 * @param
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/clientInfolistJson")
	public Map<String, Object> clientInfolistJson(DataGridModel page, String startDate, String endDate)
			throws Exception {
		if (StringUtils.isBlank(startDate) && StringUtils.isBlank(endDate)) {
			startDate = DateUtil.getDayBeforeDate(DateUtil.DATE_PATTEN_YYMMDD, 30);
		}
		if (!StringUtils.isBlank(startDate)) {
			startDate = startDate.replaceAll("-", "");
		}
		if (!StringUtils.isBlank(endDate)) {
			endDate = endDate.replaceAll("-", "");
		}
		return ipreqImsiService.getClientInfoData(page, startDate, endDate);
	}

	/**
	 * client_info用户数、下发量、回转量统计数据
	 * 
	 * @param day
	 *            日期
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getClientInfoDetail")
	public String getClientInfoDetail(Model model, String day) {
		List<IpreqImsiVO> list = ipreqImsiService.getClientInfoDetail(day);
		for (IpreqImsiVO vo : list) {
			vo.setLoginName(LoginTypeEnum.valueOf(vo.getLoginType()).getName());
		}
		model.addAttribute("list", list);
		return "/clientinfo/clientInfoDetail";
	}

}
